package biz.datalk.industrialland.common.encrypt.sm;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.security.Security;
import java.util.regex.Pattern;

/**
 * @author tarofang@163.com
 * @date 2022-05-16
 */
public class GMBaseUtil {
    static final Pattern HEX_PATTERN = Pattern.compile("^[a-fA-F0-9]+$");
    public GMBaseUtil() {
    }

    static {
        // 防止内存中出现多次BouncyCastleProvider的实例
        if (null == Security.getProvider(BouncyCastleProvider.PROVIDER_NAME)) {
            Security.addProvider(new BouncyCastleProvider());
        }
    }

    public static boolean isBlank(String str) {
        return str == null || "".equals(str.trim());
    }

    public static boolean isAnyBlank(final String... css) {
        int len = css == null ? 0 : css.length;
        if (len <= 0) {
            return false;
        }
        for (String s : css) {
            if (isBlank(s)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isHex(String str) {
        if (isBlank(str)) {
            return false;
        }
        return HEX_PATTERN.matcher(str).matches();
    }
}
